<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>login</title>
    <link href="/lib/layui-v2.6.3/css/layui.css" rel="stylesheet" type="text/css">
    <script src="/lib/layui-v2.6.3/layui.js"></script>
    <link href="/css/base.css" rel="stylesheet" type="text/css">
</head>
<body>
<style>
    .layui-form {
        margin-top: 50px;
    }

    .demo-login-container {
        width: 320px;
        margin: 21px auto 0;
    }

    .demo-login-other .layui-icon {
        position: relative;
        display: inline-block;
        margin: 0 2px;
        top: 2px;
        font-size: 26px;
    }
</style>
<form class="layui-form">
    <div class="demo-login-container">
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="text" name="memberName" value="" lay-verify="required" placeholder="会员账号"
                       lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="password" name="password" value="" lay-verify="required" placeholder="密   码"
                       lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
            </div>
        </div>
        <div class="layui-form-item layui-hide" id="tel">
            <div class="layui-input-wrap">
                <input type="text" name="tel" value=""placeholder="联系方式" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-form-item">
            <a href="#forget" style="float: right; margin-top: 7px;" id="register-members">注册会员</a>
        </div>
        <div class="layui-form-item" id="login" >
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="member-login" >立即登录</button>
        </div>
        <div class="layui-form-item layui-hide" id="register">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="member-register" >注册会员</button>
        </div>
    </div>
</form>

<script>
    layui.use(function () {
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.$;

        // 提交事件
        form.on('submit(member-login)', function (data) {
            let formData = data.field; // 获取表单字段值
            // 此处可执行 Ajax 等操作
            $.post("/member/front/login",formData,function (res){
                if (res.code==0){
                    layer.msg(res.msg,{icon:1},function (){
                        // 关闭弹出层
                        sessionStorage.setItem("memberName",formData.memberName)
                        let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                        parent.layer.close(index);
                    })
                }else {
                    layer.msg(res.msg,{icon:2})
                }
            })
            return false; // 阻止默认 form 跳转
        });

        form.on('submit(member-register)', function (data) {
            let formData= data.field; // 获取表单字段值
            // 此处可执行 Ajax 等操作
            $.post("/member/front/register",formData,function (res){
                if (res.code==0){
                    layer.msg(res.msg,{icon:1},function (){
                        // 关闭弹出层
                        let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                        parent.layer.close(index);
                    })
                }else{
                    layer.msg(res.msg,{icon:2})
                }
            })
            // 再执行关闭
            return false; // 阻止默认 form 跳转
        });

        // 注册会员
        $("#register-members").on('click', function () {
            $("#login").addClass('layui-hide')
            $("#register").removeClass('layui-hide')
            $("#register-members").addClass('layui-hide')
            $("#tel").removeClass('layui-hide')
        })


    });
</script>

</body>
</html>